package org.viettan.android.main.activities.info;

import java.util.List;

import org.viettan.android.main.R;
import org.viettan.android.main.activities.common.VietTanBaseListActivity;
import org.viettan.android.main.intents.IntentKeys;
import org.viettan.android.main.model.InfoSection;
import org.viettan.android.main.view.InfoLinkAdapter;
import org.viettan.android.main.view.InfoLinkAdapterFactory;

import android.content.Intent;
import android.content.res.Resources;
import android.view.View;
import android.widget.ListView;

import com.google.common.collect.ImmutableList;
import com.google.inject.Inject;

public class InfoActivity extends VietTanBaseListActivity {

    private final List<InfoLink> infoList = ImmutableList.of(
	    new InfoLink(LocalArticleActivity.class, R.drawable.info_aboutvt, R.string.info_aboutvt, InfoSection.ABOUT_VIET_TAN),
	    new InfoLink(LocalArticleActivity.class, R.drawable.info_websites, R.string.info_websites, InfoSection.OTHER_WEBSITES),
	    new InfoLink(LocalArticleActivity.class, R.drawable.info_contact, R.string.info_contact, InfoSection.CONTACT),
	    new InfoLink(LanguageChoiceActivity.class, R.drawable.info_language, R.string.info_language, null));

    @Inject
    InfoLinkAdapterFactory infoLinkAdapterFactory;

    private Resources res;

    @Override
    public void onResume() {
	super.onResume();

	res = getResources();

	InfoLinkAdapter adapter = infoLinkAdapterFactory.create(this, R.layout.image_one_line_row,
		infoList);
	setListAdapter(adapter);
    }

    @Override
    protected void onListItemClick(ListView listView, View view, int position, long id) {
	InfoLink infoLink = (InfoLink) getListAdapter().getItem(position);
	Intent sectionIntent = new Intent(this, infoLink.activityClass);
	sectionIntent.putExtra(IntentKeys.SECTION_ID.name(), infoLink.infoSection);
	startActivity(sectionIntent);
    }

    public class InfoLink {
	private final int imageResourceId;
	private final int titleResourceId;
	private final Class<?> activityClass;
	private final InfoSection infoSection;

	private InfoLink(Class<?> activityClass, int imageResourceId, int titleId,
		InfoSection infoSection) {
	    this.imageResourceId = imageResourceId;
	    this.titleResourceId = titleId;
	    this.activityClass = activityClass;
	    this.infoSection = infoSection;
	}

	@Override
	public String toString() {
	    return res.getString(titleResourceId);
	}

	public int getImageResourceId() {
	    return imageResourceId;
	}

	public int getTitleResourceId() {
	    return titleResourceId;
	}
    }
}
